﻿package net.steam.easyjoboa.web.action;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;

import net.steam.easyjoboa.biz.PositionBiz;
import net.steam.easyjoboa.entity.Position;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.*;

public class PositionAction {

	//接收部门ID
	private Integer id;
	//用来输出下拉框
	private String res;
	private PositionBiz positionBiz;
	@Action(value="getPositionById")
	public void getPositionById(){
		List<Position> positions = null;
		int strID=0;
		//调用上一层的根据部门ID查找部门的职位
		positions=positionBiz.findByDepartID(id);
		if(positions==null||id==0){
			res="<select style='width:90px;' name='employee.position' id='positions'>" +
			"<option>请选择职位</option></select>";
		}else if(positions.size()>0){
			res ="<select class='selectBorder' style='width: 90px;' name='positionId' id='positions'>" ;
			res +="<option>请选择职位</option>";
			for (int i = 0; i < positions.size(); i++) {
				res+="<option value='"+positions.get(i).getPositionId()+"'>"+positions.get(i).getPositionName()+"</option>";
			}
			res += "</select>";
			}
			try {
				ServletActionContext.getResponse().setCharacterEncoding("utf-8");
				//写出下拉框
				ServletActionContext.getResponse().getWriter().write(res);
			} catch (IOException e) {
				e.printStackTrace();
			}
		
	}

	public String getRes() {
		return res;
	}
	public void setRes(String res) {
		this.res = res;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public void setPositionBiz(PositionBiz positionBiz) {
		this.positionBiz = positionBiz;
	}
}
